package com.lcxw.hxzbapi.controller.paycontroller;

import com.alibaba.fastjson.JSONObject;
import com.lcxw.hxzbapi.entity.requestBean.GetVipBuyOrderInfoReqAlipay;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lcxw.hxzbapi.entity.response.Response;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/api/alipay")
@CrossOrigin
@Validated
@Slf4j
public class AlipayController {

    @Resource
    AlipayRealization alipayRealization;

    /**
     * 1、获取订单信息接口
     */
    @PostMapping("/getOrderInfo")
    public Response getOrderInfo(@RequestBody JSONObject requestParams) {

        return alipayRealization.generateOrderInfo(requestParams);
    }

    /**
     * 2、支付宝异步通知处理接口
     */
    @PostMapping("/callback")
    public void dealNotify(HttpServletRequest request, HttpServletResponse response) {

        alipayRealization.completePayment(request, response);

    }

    /**
     * 3、前端推送充值结果
     */
    @PostMapping("/payResult")
    public Response payResult(@RequestBody JSONObject requestParams) {
        return alipayRealization.dealPayResult(requestParams);
    }


    /**
     * 4、获取购买vip的订单信息接口
     */
    @PostMapping("/vip/orderInfo/get")
    public Response getVipBuyOrderInfo(
        @Valid @RequestBody GetVipBuyOrderInfoReqAlipay getVipBuyOrderInfoReqAlipay) {
        return alipayRealization.getVipBuyOrderInfo(getVipBuyOrderInfoReqAlipay);
    }

}